package com.example.myapplication;

import android.content.Context;
import android.content.SharedPreferences;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class FileSaveQQ {
    public static boolean saveUserInfo(Context context,String number,String password){
        //保存QQ账号和登录密码到data.txt文件中
        FileOutputStream fos;
        try {
            fos=context.openFileOutput("data.txt",Context.MODE_PRIVATE);
            fos.write((number+":"+password).getBytes());
            fos.close();
            return  true;
        }  catch (IOException e) {
            e.printStackTrace();
            return false;
        }
       // SharedPreferences
    }
    //从data.txt文件中获取存储的QQ账号和密码
    public static Map<String,String> getUserInfo(Context context) throws FileNotFoundException {
        String content="";
        FileInputStream fis;
        try {
            fis=context.openFileInput("data.txt");
            byte[] bufferr=new byte[fis.available()];
            fis.read(bufferr);
            Map<String,String> userMap=new HashMap<String, String>();
            String[] infos=content.split(":");
            userMap.put("number",infos[0]);
            userMap.put("password",infos[1]);
            fis.close();
            return  userMap;
        } catch (Exception e) {
            e.printStackTrace();
            return  null;
        }
    }
}
